package ylg.com.cn.youtube._data.source.remote;

import android.content.Context;
import android.support.annotation.Nullable;

import okhttp3.OkHttpClient;
import ylg.com.cn.youtube._data.User;
import ylg.com.cn.youtube._data.source.UserDataSource;

/**
 * Created by MyPC on 2017/1/11.
 */
public class UserRemoteDataSource  implements UserDataSource {
    private static final String LOGIN_URL = "http://10.0.2.2/ytb/web/app_dev.php";
    private final Context ctx;
    OkHttpClient client = new OkHttpClient();
    public UserRemoteDataSource(Context ctx) {
        this.ctx = ctx;
    }

    @Override
    public void login(@Nullable String name, @Nullable String password, final LoginCallBack callBack) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                  /*
                        加入想要从网络上获取数据，可以使用本方法
                  OkHttpClient client = new OkHttpClient();
                    Request request = new Request.Builder()
                            .url(LOGIN_URL)
                            .build();
                    Response response = client.newCall(request).execute();
                    // 服务器返回的json数据
                    String json_result = response.body().string();
                    callBack.onLoginError(json_result);*/

                    User user = new User();
                    user.name = "杨霖贵";
                    callBack.onLoginSuccess(user);

                } catch (Exception e) {
                    e.printStackTrace();

                }
            }
        }).start();
    }

    @Override
    public void register(@Nullable String name, @Nullable String password, @Nullable String phonenumber, LoginCallBack callBack) {

    }
}
